package ypmits.simpledraw {
	import ypmits.utils.SimpleMath;

	import flash.display.Sprite;
	import flash.geom.Point;

	/**
	 * @author Dave Lenz
	 */
	public class Star extends Sprite {

		private var _radius : Number;
		private var _spikesize : Number;
		private var _linesize : Number;
		private var _linecolor : uint;
		private var _fillcolor : uint;
		private var _fillcoloralpha : Number;
		
		public var param : Object = {alpha:1};

		
		public function Star( radius : Number = 50, spikesize : Number = 10, linesize : Number = 0, linecolor : uint = 0xFF0000, fillcolor : uint = 0xFF0000, fillcoloralpha : Number = 1 ) {
			_radius = radius;
			_spikesize = spikesize;
			_linesize = linesize;
			_linecolor = linecolor;
			_fillcolor = fillcolor;
			_fillcoloralpha = fillcoloralpha;
			
			redraw( );
		}

		
		public function setRadius( radius : Number ) : void {
			_radius = radius;
			redraw();
		}

		
		public function setSpikeSize( spikesize : Number ) : void {
			_spikesize = spikesize;
			redraw();
		}

		
		public function setLineColor( linecolor : Number ) : void {
			_linecolor = linecolor;
			redraw();
		}

		
		public function setFillColor( fillcolor : Number ) : void {
			_fillcolor = fillcolor;
			redraw();
		}

		
		public function setFillColorAlpha( fillcoloralpha : Number ) : void {
			_fillcoloralpha = fillcoloralpha;
			redraw();
		}

		
		
		
		
		private function redraw() : void {
			var total : Number = 30;
			var angle : Number = 360 / total;
			var innerradius : Number = _radius - _spikesize;
			var outerradius : Number = _radius;

			graphics.clear( );
			graphics.lineStyle( _linesize, _linecolor, 1 );
			graphics.beginFill( _fillcolor, _fillcoloralpha );
			var fp : Point = SimpleMath.getPointFromAngleAndDistance( 0, outerradius );
			graphics.moveTo( fp.x, fp.y );
			
			for (var i : int = 1; i < total; i++) {
				var p : Point = SimpleMath.getPointFromAngleAndDistance( angle * i, i % 2 ? innerradius : outerradius );
				graphics.lineTo( p.x, p.y );
			}
			graphics.lineTo( fp.x, fp.y );
		}
	}
}
